package org.pps.gl.client.vue;

import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * Classe représentant la page de recherche d'un utilisateur.
 * 
 */
public class RechercheDeContact extends Composite implements
		ValueChangeHandler<String> {
	DockLayoutPanel dockPanel;
	RDC_Recherche vrecherche;
	RDC_Suggestion vsuggestion;
	RDC_Visualisation vvisualisation;

	Hyperlink brecherche;
	Hyperlink bsuggestion;
	Hyperlink bvisualisation;
	ScrollPanel flux;

	public RechercheDeContact() {

		dockPanel = new DockLayoutPanel(Unit.PX);
		// dockPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		initWidget(dockPanel);
		dockPanel.setSize("100%", "100%");
		VerticalPanel menu = new VerticalPanel();

		menu.setSize("100%", "");
		menu.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
		brecherche = new Hyperlink("Recherche", "recherche");
		brecherche.setStylePrimaryName("menuHyper");
		bsuggestion = new Hyperlink("Suggestion", "suggestion");
		bsuggestion.setStylePrimaryName("menuHyper");
		bvisualisation = new Hyperlink("Visualisation", "visualisation");
		bvisualisation.setStylePrimaryName("menuHyper");

		menu.add(brecherche);
		menu.add(bsuggestion);
		menu.add(bvisualisation);

		SimplePanel p = new SimplePanel();
		p.add(menu);
		p.setStylePrimaryName("navigation");

		flux = new ScrollPanel();
		vrecherche = new RDC_Recherche();
		vsuggestion = new RDC_Suggestion();
		vvisualisation = new RDC_Visualisation();

		flux.add(vrecherche);
		History.addValueChangeHandler(this);

		flux.setSize("98%", "100%");
		dockPanel.addWest(p, 146);
		dockPanel.add(flux);
		dockPanel.setSize("100%", "100%");
	}

	@Override
	public void onValueChange(ValueChangeEvent<String> event) {
		System.out.println(event.getValue());
		String[] tab = event.getValue().split("/");

		if (event.getValue().equals("visualisation")
				|| (tab.length > 1 && tab[0] != null && tab[0].equals("user"))) {
			flux.clear();
			flux.add(vvisualisation);
		}
		if (event.getValue().equals("recherche")) {
			flux.clear();
			flux.add(vrecherche);
		}
		if (event.getValue().equals("suggestion")) {
			flux.clear();
			flux.add(vsuggestion);
		}

	}

}
